package action.concreteActions;

import grammer.LocalObject;
import grammer.Predicate;
import grammer.components.PredicateEnum;
import person.Location;
import person.PersonAchive;
import timer.Timer;
import action.ExecuteActionInterface;

/**
 * 
 * @author Minodor
 * 
 *         Used for predicates: Wakes Up, Goes To Bed
 */
public class TerminalAction extends ExecuteActionInterface {
	private boolean active;
	private Location wakeUpLocation;

	public Location getLocation() {
		return wakeUpLocation;
	}

	public TerminalAction(Timer executeTime, Predicate p) {
		super(executeTime);
		if (p.getPredicate().equals(PredicateEnum.WAKES_UP_IN)) {
			active = true;
		} else
			active = false;
		// TODO Auto-generated constructor stub
	}

	public TerminalAction(Timer executeTime, Predicate p, LocalObject l) {
		super(executeTime);
		if (p.getPredicate().equals(PredicateEnum.WAKES_UP_IN)) {
			active = true;
			wakeUpLocation = new Location();
			wakeUpLocation.setCurrent(l.getLocation());
		} else {
			active = false;
			wakeUpLocation = null;
		}
	}

	@Override
	public int execute() {
		if (PersonAchive.getPerson(this.getOnwer()) != null) {
			PersonAchive.getPerson(this.getOnwer()).setActive(active);
			if (wakeUpLocation != null)
				PersonAchive.getPerson(this.getOnwer()).setCurrentLocation(
						wakeUpLocation);
		}
		return 0;
	}

	@Override
	public int getEndTimer() {
		return executeTime.getTime();
	}

	@Override
	public int getExecuteTimer() {
		return executeTime.getTime();
	}

	@Override
	public int getStartTimer() {
		return executeTime.getTime();
	}

}
